@extends ('shop-backend::store.layout')

@section ('title','门店列表')

@section('after-styles-end')
    <style type="text/css">
        .ladda-spinner {
            position: absolute;
            margin-top: 10px;
            margin-left: 15px;
        }
    </style>
    {!! Html::style(env("APP_URL").'/assets/backend/libs/ladda/ladda-themeless.min.css') !!}
@stop

@section ('breadcrumbs')
    <h2>门店列表</h2>

    <ol class="breadcrumb">
        <li><i class="fa fa-dashboard"></i> 首页</li>
        <li>{!! link_to_route('admin.shop.list.store', '门店') !!}</li>
        <li class="active">门店列表</li>
    </ol>
@stop

@section('content')
    <div class="ibox float-e-margins">
        <div class="ibox-content" style="display: block;">
            <div class="row">
                <div class="col-md-10">
                    <div class="btn-group">
                        <a class="btn btn-primary" href="{{route('admin.shop.list.store.curd')}}">添加门店</a>
                    </div>
                    <div class="btn-group">
                        <span class="btn btn-primary" id="repairPoint" href="javascript:void(0)" style="width: 130px;">定位点修复</span>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <form method="get" action="">
                        <div class="col-sm-3" style="padding-left: 0">
                            <div class="input-group search_text">
                                <input type="text" name="name" placeholder="门店名称" value="{{!empty(request('name'))?request('name'):''}}" class="form-control">
                            </div>
                        </div>
                        <div class="col-sm-3" style="padding-left: 0">
                            <div class="input-group search_text">
                                <input type="text" name="phone" placeholder="联系方式" value="{{!empty(request('phone'))?request('phone'):''}}" class="form-control">
                            </div>
                        </div>
                        <div class="input-group-btn" style="width: 130px; margin: 2px; padding: 2px;">
                            <select class="form-control" name="tag">
                                <option value="">请选择所属标签</option>
                                @foreach($tags as $tag)
                                    <option value="{{$tag['id']}}" @if(!empty(request('tag') && request('tag')==$tag['id']))  selected @endif>{{$tag['name']}}</option>
                                @endforeach
                            </select>
                        </div>
                        <div class="input-group-btn" style="width: 130px; margin: 2px; padding: 2px;">
                            <select class="form-control" name="city">
                                <option value="">请选择城市</option>
                                @foreach($citys as $key=>$city)
                                    <option value="{{$key}}" @if(!empty(request('city')) && request('city')==$key) selected @endif>{{$city}}</option>
                                @endforeach
                            </select>
                        </div>
                        <span class="input-group-btn">
                            <button type="submit" class="btn btn-primary">查找</button>
                        </span>
                    </form>
                </div>
            </div>
            <div class="hr-line-dashed"></div>
            <table class="table table-striped table-bordered table-hover">
                <thead>
                    <tr>
                        <th>店铺名称</th>
                        <th>店铺联系方式</th>
                        <th>所属城市</th>
                        <th>所属标签</th>
                        <th>置顶</th>
                        <th>启用店铺</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    @if (!empty($data))
                        @foreach ($data as $v)
                            <tr>
                        <td>{!! $v->name !!}</td>
                        <td>{!! $v->phone !!}</td>
                        <td>@if(isset($v->cityInfo->name) && $v->cityInfo->name) {!! $v->cityInfo->name !!} @endif</td>
                                @if(is_string($v->tag))
                                    <td>{!! $v->tag !!}</td>
                                @else
                                    @foreach ($v->tag as $vt)
                                        <td><img src='{!! $vt->file_url !!}' /></td>
                                    @endforeach
                                @endif
                                <td>{!! $v->top == 1 ? '是' : '否'  !!}</td>
                        <td>{!! $v->is_enable == 1 ? '启用' : '禁用' !!}</td>
                        <td>
                            <a href="{!!route('admin.shop.list.store.curd', ['id' => $v->id])!!}" class="btn btn-xs btn-primary"><i class="fa fa-pencil" data-toggle="tooltip" data-placement="top" title="" data-original-title="编辑"></i></a>
                            <a class="btn btn-xs btn-danger" style="cursor:pointer;" onclick="del_store({!!$v-> id!!});"><i class="fa fa-trash" data-toggle="tooltip" data-placement="top" title="" data-original-title="删除"></i></a>
                        </td>
                    </tr>
                        @endforeach
                    @endif
                </tbody>
            </table>
            {!! $data->render() !!}
            <div class="pull-right">
            </div>
            <div class="clearfix"></div>
        </div>
    </div>
@stop
@section('after-scripts-end')
    {!! Html::script(env("APP_URL").'/assets/wechat-backend/libs/ladda/spin.min.js') !!}
    {!! Html::script(env("APP_URL").'/assets/wechat-backend/libs/ladda/ladda.min.js') !!}
    {!! Html::script(env("APP_URL").'/assets/wechat-backend/libs/ladda/ladda.jquery.min.js') !!}
    <script>
    function del_store(id) {
        if (confirm('确定删除此项？')) {
            $.ajax({
                type: 'POST',
                url: "{!!route('store.ajax.del')!!}",
                data: {'id': id, 'type': 'list'},
                dataType: 'json',
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                },
                success: function (data) {
                    location.reload();
                }
            });
        }
    }

    $('#repairPoint').on('click', function () {
        $.ajax({
            type: 'GET',
            url: '{!! route('admin.shop.store.point') !!}',
            dataType: 'json',
            beforeSend: function () {
                $('#repairPoint').ladda().ladda('start');
            },
            success: function (res) {
                $('#repairPoint').ladda().ladda('stop');
                $('.ladda-progress').remove();
                $('.ladda-spinner').remove();
                if (200 == res.code) {
                    swal("修复成功", res.message, "success");
                }
            }
        });
    });
</script>
@stop